<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="">
        <input type="text" name="username" value="admin">
        <input type="text" name="password" value="123">

        <input type="submit" value="提交">
    </form>
    <script src="/upload/ajax.js"></script>

    <script>
        var form = document.querySelector("form");

        form.addEventListener("submit", function (e) {
            // 阻止默认事件
            e.preventDefault();
            // FormData在js中提供了一个构造函数
            // 接收表单实例作为参数
            var fd = new FormData(form);

            fd.append("sex","f");
            // console.log(...fd);

            ajax({
                url: "/form-data",
                method: "post",
                contentType: false,
                processData: false,
                data: fd,
                success: function(data){
                    console.log(data);
                }
            })

        });
    </script>
</body>

</html>